<script setup>
import {
    Management,
    Promotion,
    UserFilled,
    User,
    Crop,
    EditPen,
    SwitchButton,
    CaretBottom
} from '@element-plus/icons-vue'
import avatar from '@/assets/default.png'


import {userInfoService} from '@/api/user.js'
import useUserInfoStore from '@/stores/userInfo.js'
import {useTokenStore} from '@/stores/token.js'
const tokenStore = useTokenStore();
const userInfoStore = useUserInfoStore();

const isSubMenuVisible = ref(0)
//调用函数,获取用户详细信息
const getUserInfo = async()=>{
    //调用接口
    let result = await userInfoService();
    //数据存储到pinia中
    userInfoStore.setInfo(result.data);
    console.log(result.data.id)
    if(result.data.id ==4){
      isSubMenuVisible.value=1;
    }
}

getUserInfo();



//条目被点击后,调用的函数
import {useRouter} from 'vue-router'
const router = useRouter();
import {ElMessage,ElMessageBox} from 'element-plus'
import {ref} from "vue";

const handleCommand =(command)=>{
    if(command ==='logout'){

    }else{
        router.push('/user/'+command)
    }
} 


</script>

<template>
    <el-container class="layout-container">
        <!-- 左侧菜单 -->
        <el-aside width="200px">
            <div class="el-aside__logo"></div>
            <el-menu active-text-color="#ffd04b" background-color="#232323"  text-color="#fff"
                router>
            
                <el-sub-menu index="2" v-if="isSubMenuVisible.valueOf()===0">
                    <template #title>
                        <el-icon>
                            <Management />
                        </el-icon>
                        <span>数据管理</span>
                    </template>
                    <el-menu-item index="/data/history">
                        <el-icon>
                            <User />
                        </el-icon>
                        <span>历史数据</span>
                    </el-menu-item>
                    <el-menu-item index="/data/channel">
                        <el-icon>
                            <Crop />
                        </el-icon>
                        <span>渠道数据</span>
                    </el-menu-item>
                </el-sub-menu>

                <el-sub-menu index="3" v-if="isSubMenuVisible.valueOf()===0">
                    <template #title>
                        <el-icon>
                            <Management />
                        </el-icon>
                        <span>订单管理</span>
                    </template>
                    <el-menu-item index="/order/member">
                        <el-icon>
                            <User />
                        </el-icon>
                        <span>会员订单</span>
                    </el-menu-item>

                </el-sub-menu>

                <el-sub-menu index="4" v-if="isSubMenuVisible.valueOf()===0">
                    <template #title>
                        <el-icon>
                            <Management />
                        </el-icon>
                        <span>题库管理</span>
                    </template>
                    <el-menu-item index="/question/question">
                        <el-icon>
                            <User />
                        </el-icon>
                        <span>奇奇屋</span>
                    </el-menu-item>
                    <el-menu-item index="/question/knowledge">
                        <el-icon>
                            <Crop />
                        </el-icon>
                        <span>妙妙屋</span>
                    </el-menu-item>
                  <el-menu-item index="/question/questionData">
                    <el-icon>
                      <Crop />
                    </el-icon>
                    <span>学生做题查询</span>
                  </el-menu-item>
                  <el-menu-item index="/question/knowledgeData">
                    <el-icon>
                      <Crop />
                    </el-icon>
                    <span>学生知识点查询</span>
                  </el-menu-item>
                </el-sub-menu>
              <el-sub-menu index="8" v-if="isSubMenuVisible.valueOf()===0">
                <template #title>
                  <el-icon>
                    <Management />
                  </el-icon>
                  <span>用户管理</span>
                </template>
                <el-menu-item index="/user/account">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>账号管理</span>
                </el-menu-item>
              </el-sub-menu>
              <el-sub-menu index="9" v-if="isSubMenuVisible.valueOf()===0">
                <template #title>
                  <el-icon>
                    <Management />
                  </el-icon>
                  <span>资源管理</span>
                </template>
                <el-menu-item index="/resource/publish">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>用户发布资源</span>
                </el-menu-item>
                <el-menu-item index="/resource/information">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>用户信息资源</span>
                </el-menu-item>
                <el-menu-item index="/resource/memberOrder">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>会员订单资源</span>
                </el-menu-item>
                <el-menu-item index="/resource/interestConfig">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>兴趣圈配置</span>
                </el-menu-item>
              </el-sub-menu>

                <el-sub-menu index="5">
                    <template #title>
                        <el-icon>
                            <Management />
                        </el-icon>
                        <span>兴趣圈管理</span>
                    </template>
                    <el-menu-item index="/interest/publishData" v-if="isSubMenuVisible.valueOf()===0">
                        <el-icon>
                            <User />
                        </el-icon>
                        <span>发布数据统计</span>
                    </el-menu-item>
                    <el-menu-item index="/interest/userData" v-if="isSubMenuVisible.valueOf()===0">
                        <el-icon>
                            <Crop />
                        </el-icon>
                        <span>用户数据统计</span>
                    </el-menu-item>
                  <el-menu-item index="/interest/publishRecord">
                    <el-icon>
                      <Crop />
                    </el-icon>
                    <span>发布管理</span>
                  </el-menu-item>

                  <el-menu-item index="/interest/popular">
                    <el-icon>
                      <Crop />
                    </el-icon>
                    <span>热门管理</span>
                  </el-menu-item>

                  <el-menu-item index="/interest/friends" v-if="isSubMenuVisible.valueOf()===0">
                    <el-icon>
                      <Crop />
                    </el-icon>
                    <span>好友管理</span>
                  </el-menu-item>
                </el-sub-menu>
              <el-sub-menu index="10" v-if="isSubMenuVisible.valueOf()===0">
                <template #title>
                  <el-icon>
                    <Management />
                  </el-icon>
                  <span>积分管理</span>
                </template>
                <el-menu-item index="/point/teaching">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>教学积分查询</span>
                </el-menu-item>

                <el-menu-item index="/point/teachingDetail">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>教学积分获取详情</span>
                </el-menu-item>

                <el-menu-item index="/point/user">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>用户积分管理</span>
                </el-menu-item>
              </el-sub-menu>
              <el-sub-menu index="20" v-if="isSubMenuVisible.valueOf()===0">
                <template #title>
                  <el-icon>
                    <Management />
                  </el-icon>
                  <span>树洞管理</span>
                </template>
                <el-menu-item index="/user/treeHole">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>树洞审批</span>
                </el-menu-item>
              </el-sub-menu>

              <el-sub-menu index="21" v-if="isSubMenuVisible.valueOf()===0">
                <template #title>
                  <el-icon>
                    <Management />
                  </el-icon>
                  <span>活动管理</span>
                </template>
                <el-menu-item index="/activity/activity">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>活动管理</span>
                </el-menu-item>

                <el-menu-item index="/activity/resource">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>活动资源管理</span>
                </el-menu-item>
              </el-sub-menu>

              <el-sub-menu index="22" v-if="isSubMenuVisible.valueOf()===0">
                <template #title>
                  <el-icon>
                    <Management />
                  </el-icon>
                  <span>抽奖管理</span>
                </template>
                <el-menu-item index="/lottery/lottery">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>抽奖类目管理</span>
                </el-menu-item>

                <el-menu-item index="/lottery/resource">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>抽奖奖项管理</span>
                </el-menu-item>
              </el-sub-menu>

              <el-sub-menu index="23" v-if="isSubMenuVisible.valueOf()===0">
                <template #title>
                  <el-icon>
                    <Management />
                  </el-icon>
                  <span>世界消息管理</span>
                </template>
                <el-menu-item index="/world/messageResource">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>消息资源管理</span>
                </el-menu-item>
              </el-sub-menu>

              <el-sub-menu index="24" v-if="isSubMenuVisible.valueOf()===0">
                <template #title>
                  <el-icon>
                    <Management />
                  </el-icon>
                  <span>好奇星管理</span>
                </template>
                <el-menu-item index="/home/ship">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>飞船管理</span>
                </el-menu-item>

                <el-menu-item index="/home/ship/level">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>飞船等级管理</span>
                </el-menu-item>

                <el-menu-item index="/home/ship/knowledge">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>飞船知识管理</span>
                </el-menu-item>

                <el-menu-item index="/home/tree">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>生命之树管理</span>
                </el-menu-item>

                <el-menu-item index="/home/tree/shape">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>生命之树形态管理</span>
                </el-menu-item>

                <el-menu-item index="/home/tree/level">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>生命之树等级管理</span>
                </el-menu-item>

                <el-menu-item index="/home/background">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>家园背景管理</span>
                </el-menu-item>

                <el-menu-item index="/home/backgroundEffects">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>家园背景特效管理</span>
                </el-menu-item>

                <el-menu-item index="/home/message/resource">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>外星人/小狗话术管理</span>
                </el-menu-item>
              </el-sub-menu>


                <el-sub-menu index="6" v-if="isSubMenuVisible.valueOf()===0">
                    <template #title>
                        <el-icon>
                            <Management />
                        </el-icon>
                        <span>其他设置</span>
                    </template>
                    <el-menu-item index="/setup/versionSeason">
                        <el-icon>
                            <User />
                        </el-icon>
                        <span>版本/赛事设置</span>
                    </el-menu-item>

                    <el-menu-item index="/setup/level">
                        <el-icon>
                            <Crop />
                        </el-icon>
                        <span>等级详情</span>
                    </el-menu-item>
                    <el-menu-item index="/setup/milestone">
                        <el-icon>
                            <Crop />
                        </el-icon>
                        <span>里程碑详情</span>
                    </el-menu-item>

                </el-sub-menu>
              <el-sub-menu index="7" v-if="isSubMenuVisible.valueOf()===0">
                <template #title>
                  <el-icon>
                    <Management />
                  </el-icon>
                  <span>日志管理</span>
                </template>
                <el-menu-item index="/log/trace">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>用户跟踪日志</span>
                </el-menu-item>
              </el-sub-menu>
              <el-sub-menu index="13" v-if="isSubMenuVisible.valueOf()===0">
                <template #title>
                  <el-icon>
                    <Management />
                  </el-icon>
                  <span>浏览记录管理</span>
                </template>
                <el-menu-item index="/browse/userBrowse">
                  <el-icon>
                    <User />
                  </el-icon>
                  <span>用户浏览记录</span>
                </el-menu-item>
              </el-sub-menu>
            </el-menu>
        </el-aside>
        <!-- 右侧主区域 -->
        <el-container>
            <!-- 头部区域 -->
            <el-header>
                <div>用户：<strong>{{ userInfoStore.info.nickname }}</strong></div>

            </el-header>
            <!-- 中间区域 -->
            <el-main>
                <!-- <div style="width: 1290px; height: 570px;border: 1px solid red;">
                    内容展示区
                </div> -->
                <router-view></router-view>
            </el-main>
            <!-- 底部区域 -->

        </el-container>
    </el-container>
</template>

<style lang="scss" scoped>
.layout-container {
    height: 100vh;

    .el-aside {
        background-color: #232323;

        &__logo {
            height: 120px;
            background: url('@/assets/logo.png') no-repeat center / 120px auto;
        }

        .el-menu {
            border-right: none;
        }
    }

    .el-header {
        background-color: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .el-dropdown__box {
            display: flex;
            align-items: center;

            .el-icon {
                color: #999;
                margin-left: 10px;
            }

            &:active,
            &:focus {
                outline: none;
            }
        }
    }

    .el-footer {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        color: #666;
    }
}
</style>